package com.baoyi.landscape;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

/**
 * 中国山水画主界面
 * 
 * @author Administrator
 * 
 */
public class MainUI extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		// Intent intet = new Intent();
		// intet.setClass(MainUI.this, TestListView.class);
		// startActivity(intet);
		/** 全屏设置，隐藏窗口所有装饰 */
		// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		// WindowManager.LayoutParams.FLAG_FULLSCREEN);

		picbutton = (Button) findViewById(R.id.picbutton);
		gallerybutton = (Button) findViewById(R.id.gallerybutton);
		aboutbutton = (Button) findViewById(R.id.aboutbutton);
		aboutbutton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent item = new Intent(MainUI.this, AboutArtistUI.class);
				// startActivityForResult(item, RESULT_OK);
				startActivity(item);

			}
		});
		picbutton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent item = new Intent(MainUI.this, AboutLandscapeUI.class);
				// startActivityForResult(item, RESULT_OK);
				startActivity(item);

			}
		});
		gallerybutton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent item = new Intent(MainUI.this, WorkListUI.class);
				if (!BaoyiApplication.getInstance().isonline()) {
					Toast.makeText(MainUI.this, "请检查你的网络连接！",
							Toast.LENGTH_SHORT).show();

				} else {
					startActivity(item);
				}

			}
		});
	}

	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		menu = (Menu) findViewById(R.menu.mainmenu);
		return true;
	}

	public void watchWork() {

		final Handler handler = new Handler();
		Runnable runnable = new Runnable() {
			@Override
			public void run() {

				dismissDialog(2);
			}
		};
		handler.postDelayed(runnable, 2000);
		// handler.removeCallbacks(runnable);

	}

	@Override
	protected Dialog onCreateDialog(int id) {
		switch (id) {
		case 1: {
			ProgressDialog dialog = new ProgressDialog(this);
			dialog.setTitle("Indeterminate");
			dialog.setMessage("Please wait while loading...");
			dialog.setIndeterminate(true);
			dialog.setCancelable(true);
			return dialog;
		}
		case 2: {
			ProgressDialog dialog = new ProgressDialog(this);
			dialog.setMessage("正在为你加载内容，请等待...");
			dialog.setIndeterminate(true);
			dialog.setCancelable(true);
			return dialog;
		}
		}
		return null;
	}

	/**
	 * 中国山水画介绍按钮
	 */
	private Button picbutton;
	/**
	 * 进入作品按钮
	 */
	private Button gallerybutton;
	/**
	 * 关于作者按钮
	 */
	private Button aboutbutton;
}